<#macro queryCondition>
    <#nested >
    <div id="noCondition" class="layui-col-md12 layui-badge layui-bg-gray" style="height: 24px;line-height: 24px;padding: 0;">
        无更多查询条件
    </div>
</#macro>

<#macro queryAct>
<script type="text/html" id="toolbar">
    <#nested >
</script>
</#macro>
<#macro commonQuery>
    <div class="layui-col-md12">
        <div class="layui-input-search">
            <i class="layui-icon layui-icon-search"></i>
            <input type="text" id="filter" placeholder="请输入过滤条件" autocomplete="off" class=""/>
            <div class="layui-btn-group search-group">
                <a id="searchBtn" class="layui-btn layui-btn-normal">搜索</a>
                <a id="moreBtn" class="layui-btn layui-btn-normal btn-more" title="更多条件">
                    <i class="layui-icon layui-icon-up"></i>
                </a>
            </div>
        </div>
    </div>
</#macro>
<#macro tableAct>
    <script type="text/html" id="rowBar">
        <#nested >
    </script>
</#macro>
<#macro queryScript name editUrl queryUrl delUrl viewUrl>
    <script type="application/javascript">
        var closeLayer;
        var loadFunc;
        var add;
        //UI初始化
        layui.use(['element', 'form', 'table', 'layer'], function () {
            var table = layui.table;
            var layer = layui.layer;
            var layerIndex;
            loadFunc = function () {
                var conditions = $("#conditions");
                var newData = {};
                var moreCon = $("#moreBtn i.layui-icon-up").length > 0 ? true : false;
                newData["filter"] = $("input[id='filter']").val();
                if (moreCon) {
                    $.each($("input[name]", conditions), function (index, dom) {
                        //剔除selectPlus
                        if ($(dom).attr("name").indexOf("selectPlus") < 0) {
                            newData[$(dom).attr("name")] = $(dom).val();
                        }
                    });
                    $.each($("select[name]", conditions), function (index, dom) {
                        //剔除selectPlus
                        if ($(dom).attr("name").indexOf("selectPlus") < 0) {
                            newData[$(dom).attr("name")] = $(dom).val();
                        }
                    });
                }
                table.reload('page', {
                    where: newData
                })
            };
            var toggleMore = function () {
                var doms = $(this).parent().parent().parent().nextAll();
                var $that = $(this);
                if (doms.length > 1) {
                    doms.filter("#noCondition").remove();
                }
                $.each(doms, function (index) {
                    if (index == doms.length) {
                        return;
                    }
                    $(this).toggle();
                });

                $("i", $that).toggleClass("layui-icon-down");
                $("i", $that).toggleClass("layui-icon-up");
            };
            closeLayer = function () {
                layer.close(layerIndex);
            };
            $("#searchBtn").on("click", loadFunc);
            $("#moreBtn").on("click", toggleMore);
            $("#moreBtn").click();

            add = function () {
                layerIndex = layer.open({
                    type: 2,
                    title: '新增',
                    area: ['95%', '90%'],
                    content: '${editUrl}',
                    end: function () {
                        loadFunc();
                    }
                });
            };
            table.render({
                elem: '#page'
                , url: '${queryUrl}'
                ,toolbar: '#toolbar'
                , where: {
                    filter: $("#filter").val()
                }
                , cols: [<#nested >]
                , response: {
                    statusCode: 1 //规定成功的状态码，默认：0
                    , dataName: 'rows' //规定数据列表的字段名称，默认：data
                }
                , page: true
            });
            table.on('toolbar(page)', function(obj){
                if (typeof window[obj.event] === "function") {
                    window[obj.event].call(this, obj)
                }
            });

            //监听工具条
            table.on('tool(page)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确定删除吗?', function (index) {
                        $.ajax({
                            url: "${delUrl}",
                            method: "GET",
                            data: {
                                id: data.id
                            },
                            success: function (result) {
                                layui.use('layer', function () {
                                    var layer = layui.layer;
                                    layer.msg(result.msg);
                                    $("#searchBtn").click();
                                });
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    //newTab("${editUrl}?id=" + data.id, "修改${name!}-" + data.id);
                    layerIndex = layer.open({
                        type: 2,
                        title: '修改',
                        area: ['95%', '90%'],
                        content: "${editUrl}?id=" + data.id,
                        end: function () {
                            loadFunc();
                        }
                    });
                } else if (obj.event === 'view') {
                    //newTab("${editUrl}?id=" + data.id, "修改${name!}-" + data.id);
                    layerIndex = layer.open({
                        type: 2,
                        title: '查看',
                        area: ['95%', '90%'],
                        content: "${viewUrl}?id=" + data.id
                    });
                } else {
                    if (typeof window[obj.event] === "function") {
                        window[obj.event].call(this, obj)
                    }

                }
            });
        });

    </script>
</#macro>